#region

using System;
using System.Drawing;
using System.Windows.Forms;
using TextEditor.Util;

#endregion

namespace EditeurSyntaxiqueVocal.Intellisencs
{
    /// <summary>
    /// 
    /// </summary>
    public class IntellisenceDescripteur : Form
    {
        private readonly Completion completion;
        private string description = String.Empty;
        public bool HideOnClick;

        public IntellisenceDescripteur(Completion completion)
        {
            this.completion = completion;
            Owner = completion;
            SetStyle(ControlStyles.Selectable, false);
            StartPosition = FormStartPosition.Manual;
            FormBorderStyle = FormBorderStyle.None;
            ShowInTaskbar = false;
            //base.CreateHandle();
            completion.LocationChanged += completion_LocationChanged;
            completion.VisibleChanged += completion_VisibleChanged;
        }

        protected override bool ShowWithoutActivation
        {
            get { return true; }
        }

        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        private void completion_VisibleChanged(object sender, EventArgs e)
        {
            completion_LocationChanged(null, null);
            Visible = completion.Visible;
        }

        private void completion_LocationChanged(object sender, EventArgs e)
        {
            Location = completion.Location + new Size(completion.Width, 0);
        }

        public void ShowDeclarationViewWindow()
        {
            Show();
        }

        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);
            if (HideOnClick) Hide();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            if (!string.IsNullOrEmpty(description))
                TipPainterTools.DrawHelpTipFromCombinedDescription(this, pe.Graphics, Font, null,
                                                                   description);
        }

        protected override void OnPaintBackground(PaintEventArgs pe)
        {
            pe.Graphics.FillRectangle(SystemBrushes.Info, pe.ClipRectangle);
        }
    }
}